[deps.host]
stage0_gcc

[mirrors]
http://www.etalabs.net/musl/releases/musl-1.1.3.tar.gz
http://www.musl-libc.org/releases/musl-1.1.3.tar.gz

[main]
filesize=844982
sha512=c580c700d609eced15dc398ff6dcbc2e38fab24eaa5ea80a58c3d41d9f749579cce328bbad149f2b5975533d6ec051e6cc08be3bea4d65e143fc850745bf24c2

[build]
# do not rebuild stage0 packages once we're past that stage
test "$STAGE" = "0" || exit 0

patch -p1 < "$K"/musl-1.1.3-mips-regression.patch || exit 1

CC=$R/bin/gcc ./configure --enable-gcc-wrapper \
  --prefix=$butch_prefix --syslibdir=$butch_prefix/lib || exit 1

# enable debug libc when DEBUGBUILD is set
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS += -O0 -g" >> config.mak
[ ! -z "$DEBUGBUILD" ] && echo "CFLAGS_ALL_SHARED += -O0 -g" >> config.mak

make CC=$R/bin/gcc -j$MAKE_THREADS || exit 1
make install DESTDIR="$butch_install_dir" || exit 1

dest="$butch_install_dir""$butch_prefix"

# generate a musl-gcc wrapper that is aware of our directory layout...
cat << EOF > "$dest"/bin/musl-gcc
#!/bin/sh 
self=\`readlink -f "\$0"\`
selfdir=\`dirname "\$self"\`/../../../bin
exec "\$selfdir/rawcc" "\$@" -specs "\$selfdir/../lib/musl-gcc.specs"
EOF

chmod +x "$dest"/bin/musl-gcc

# fix paths in spec file
sed -i 's,/lib,'"$butch_root_dir"'/lib,g' "$dest"/lib/musl-gcc.specs
sed -i 's,/include,'"$butch_root_dir"'/include,g' "$dest"/lib/musl-gcc.specs
sed -i 's,/lib/ld-musl,/xxx/xxx/,' "$dest"/lib/musl-gcc.specs

